package com.qq.API_日期与时间.JDK8;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.MonthDay;
import java.time.YearMonth;

//LocalDate localDate = LocalDate.now();//日期对象
//LocalDate localDate = LocalDate.of(2022,11,22);调用静态方法，指定日期创建对象
//LocalDate nowDate = LocalDate.from(Temporal);//提取来自其他日期对象的日期来创建对象

public class API_LocalDate {
    public static void main(String[] args) {
        // 1、创建本地日期对象。
        LocalDate nowDate = LocalDate.now();
        System.out.println("今天的日期：" + nowDate);//今天的日期：
        
        YearMonth YM = YearMonth.now();//年月对象
        MonthDay MD = MonthDay.now();//月日对象
        
        //单独获取年
        int year = nowDate.getYear();
        System.out.println("year：" + year);
        
        //单独获取月（月能获取枚举类型）
        int month = nowDate.getMonthValue();
        int month1 = nowDate.getMonth().getValue();//调用getValue返回int，和getMonthValue()效果一样
        Month month2 = nowDate.getMonth();//返回枚举类型数据
        System.out.println("month：" + month);
        System.out.println(month2);

        //单独获取日
        int day = nowDate.getDayOfMonth();
        System.out.println("day：" + day);

        //一年的第几天
        int dayOfYear = nowDate.getDayOfYear();
        System.out.println("dayOfYear：" + dayOfYear);
        
        //获取星期几(星期能获取枚举类型)
        int Week = nowDate.getDayOfWeek().getValue();//调用getValue返回int，不然是枚举类
        DayOfWeek Week1 =  nowDate.getDayOfWeek();
        System.out.println("Week：" + Week);

        System.out.println("------------------------");
        //2、创建指定日期对象。
        LocalDate bt = LocalDate.of(1991, 11, 11);//指定日期创建对象，传入对应的年月日
        System.out.println(bt);
        System.out.println(LocalDate.of(1991, Month.NOVEMBER, 11));//也可以把月换成枚举形
        
        int month4 = bt.getMonthValue();//一样可以调用日期的各种方法
        System.out.println(month4);
        
        //提取来自其他日期对象的日期
        LocalDateTime a  = LocalDateTime.now();
        LocalDate nowDate1 = LocalDate.from(a);
        System.out.println(nowDate1);
    }
}
